package com.yjhealth.libs.businessdemo.adapter;

import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yjhealth.libs.businessdemo.R;
import com.yjhealth.libs.businessdemo.databinding.BusinessdemoItemViewholderBinding;
import com.yjhealth.libs.core.utils.EffectUtil;
import com.yjhealth.libs.core.view.recyclerview.adapter.ItemViewDelegate;

import java.util.ArrayList;

public class DemoViewDelegate extends ItemViewDelegate<String> {
    /*Default*/
    /*Util*/
    /*Flag*/
    /*View*/
    private BusinessdemoItemViewholderBinding binding;

    @Override
    public void onCreateViewHolder(@NonNull ViewGroup parent) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.businessdemo_item_viewholder, parent, false);
        root = binding.getRoot();
    }

    @Override
    public boolean isForViewType(@NonNull ArrayList<String> datas, int position) {
        return true;
    }

    @Override
    public void onBindViewHolder(@NonNull final ArrayList<String> datas, final int position) {
        String str = datas.get(position);
        binding.tvText.setText(str);
        EffectUtil.addClickEffect(binding.tvText);
        binding.tvText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemViewClick(binding.tvText, datas, position);
                }
            }
        });
        binding.tvText.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (onItemClickListener != null) {
                    return onItemClickListener.onItemViewLongClick(binding.tvText, datas, position);
                }
                return false;
            }
        });
    }
}
